/**
 * UserFavoriteController
 *
 * 主要职责：
 * - 用户收藏（歌曲/歌单）：收藏、取消、查看收藏列表
 *
 * 关键接口示例：
 * - Response favoriteSong(Long songId)
 * - Response listFavorites(PageParam p)
 *
 * 依赖项：
 * - IUserFavoriteService
 *
 * 答辩要点：
 * - 用户-资源唯一索引设计以防止重复收藏，以及收藏计数的并发处理
 */
package net.zjitc.yqmusicserver.controller;

import jakarta.validation.Valid;
import net.zjitc.yqmusicserver.domain.dto.PlaylistDTO;
import net.zjitc.yqmusicserver.domain.dto.SongDTO;
import net.zjitc.yqmusicserver.domain.vo.PlaylistVO;
import net.zjitc.yqmusicserver.domain.vo.SongVO;
import net.zjitc.yqmusicserver.result.PageResult;
import net.zjitc.yqmusicserver.result.Result;
import net.zjitc.yqmusicserver.service.IUserFavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author 罗翼侨
 * @date 2025/6/17 13:50
 */
@RestController
@RequestMapping("/favorite")
public class UserFavoriteController {
    @Autowired
    private IUserFavoriteService userFavoriteService;

    /**
     * 获取用户收藏的歌曲列表
     *
     * @return 用户收藏的歌曲列表
     */
    @PostMapping("/getFavoriteSongs")
    public Result<PageResult<SongVO>> getUserFavoriteSongs(@RequestBody @Valid SongDTO songDTO) {
        return userFavoriteService.getUserFavoriteSongs(songDTO);
    }

    /**
     * 收藏歌曲
     *
     * @param songId 歌曲id
     * @return 收藏结果
     */
    @PostMapping("/collectSong")
    public Result collectSong(@RequestParam Long songId) {
        return userFavoriteService.collectSong(songId);
    }

    /**
     * 取消收藏歌曲
     *
     * @param songId 歌曲id
     * @return 取消收藏结果
     */
    @DeleteMapping("/cancelCollectSong")
    public Result cancelCollectSong(@RequestParam Long songId) {
        return userFavoriteService.cancelCollectSong(songId);
    }

    /**
     * 获取用户收藏的歌单列表
     *
     * @return 用户收藏的歌单列表
     */
    @PostMapping("/getFavoritePlaylists")
    public Result<PageResult<PlaylistVO>> getFavoritePlaylists(@RequestBody @Valid PlaylistDTO playlistDTO) {
        return userFavoriteService.getUserFavoritePlaylists(playlistDTO);
    }

    /**
     * 收藏歌单
     *
     * @param playlistId 歌单id
     * @return 收藏结果
     */
    @PostMapping("/collectPlaylist")
    public Result collectPlaylist(@RequestParam Long playlistId) {
        return userFavoriteService.collectPlaylist(playlistId);
    }

    /**
     * 取消收藏歌单
     *
     * @param playlistId 歌单id
     * @return 取消收藏结果
     */
    @DeleteMapping("/cancelCollectPlaylist")
    public Result cancelCollectPlaylist(@RequestParam Long playlistId) {
        return userFavoriteService.cancelCollectPlaylist(playlistId);
    }
}
